//
//  EFCurAddressCell.m
//  EnjogFood
//
//  Created by guocheng on 2017/5/4.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFCurAddressCell.h"
#import "EFCurAddressItem.h"

@interface EFCurAddressCell()

@property(strong,nonatomic) UILabel* addressLabel;
@property(strong,nonatomic) UIImageView* locationIV;
@property(strong,nonatomic) UIButton* relocateBtn;

@end

@implementation EFCurAddressCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = RGBCOLOR(0xffffff);
        [self initView];
    }
    return self;
}

-(void)setObject:(EFCurAddressItem *)item{
    [_addressLabel setText:item.location];
}

-(void)initView{
    [self.contentView addSubview:self.relocateBtn];
    [self.contentView addSubview:self.addressLabel];
    [self.contentView addSubview:self.locationIV];
}


-(void)layoutSubviews{
    self.addressLabel.top = 10;
    self.addressLabel.left = 20;
    self.addressLabel.height = 17;
    self.addressLabel.width = kScreenWidth - self.locationIV.width - self.relocateBtn.width  - 22 - 4;
    
    self.relocateBtn.top = 10;
    self.relocateBtn.left = kScreenWidth  - 90;
    self.relocateBtn.width = 90;
    self.relocateBtn.height = 17;
    
    self.locationIV.top = 10;
    self.locationIV.right = self.relocateBtn.left - 10;
    self.locationIV.width = 18;
    self.locationIV.height = 18;
}

-(void)onClickRelacate{
    [APP_CONTEXT.locationManager startLocation];
    if(self.relocateblock){
        self.relocateblock();
    }
}

-(UIButton*)relocateBtn{
    if(_relocateBtn == NULL){
        _relocateBtn = [[UIButton alloc] init];
        [_relocateBtn setTitleColor:kBlack666 forState:UIControlStateNormal];
        _relocateBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        _relocateBtn.titleLabel.textColor = kBlack666;
        [_relocateBtn setTitle:@"重新定位" forState:UIControlStateNormal];
        [_relocateBtn addTarget:self action:@selector(onClickRelacate) forControlEvents:UIControlEventTouchUpInside];
    }
    return _relocateBtn;
}
-(UIImageView*)locationIV{
    if(_locationIV == NULL){
        _locationIV = [[UIImageView alloc] init];
        [_locationIV setImage:IMG(@"content_icon_location")];
    }
    return _locationIV;
}

-(UILabel*)addressLabel{
    if(_addressLabel == NULL){
        _addressLabel = [[UILabel alloc] init];
        _addressLabel.font = [UIFont systemFontOfSize:15];
        _addressLabel.textColor =kBlack666;
    }
    return _addressLabel;
}


@end
